<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;
use app\admin\model\Articles;
use app\admin\controller\blog\Sorts;

//use app\common\controller\Backend;
class Article extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $url = $this->request->request('url');
        $aid = $this->request->request('aid')?$this->request->request('aid'):"";
        $this->comments = new \app\admin\model\Comments;
        $this->articles = new \app\admin\model\Articles;
        $this->sorts = new \app\admin\model\Sorts;
        $this->labels = new \app\admin\model\Labels;
        //获取文章信息
        $article = $this->articles
        ->alias('articles')
            ->with(['blogsorts', 'bloglabels'])
            ->where(['status'=> 1,'articles.id'=>$aid])
            ->find();
            $totalcomments = $this->comments
                ->where('article_id', '=', $article['id'])
                ->count();
            $article->totalcomments = $totalcomments;
           // $article->article_content = strip_tags($article['article_content']);
            $article->bloglabels=$this->labels->where('id','in',$article['labels_ids'])->select();
        //热门列表
       $hotlist = $this->articles->hotarticlelist();
        //导航分类列表
        $topsortslist = $this->sorts->gettopsortslist();
        //获取当前时间
        $getnowdate=new \app\index\controller\Common();
        //当前栏目
        $category=$this->sorts->where('id',$article['sorts_ids'])->find();
        // 模板变量赋值
        $this->assign('article', $article);
        $this->assign('hotlist', $hotlist);
        $this->assign('topsortslist', $topsortslist);
        $this->assign('category', $category);
        
        $this->assign('nowdate', $getnowdate->getnowdate());

        // 渲染模板输出
        return $this->view->fetch();
    }

}
